package com.laotou99.backjack.test;

public class Clerk {
	
	private int product = -1;
	
	public synchronized void setProduct(int product){
		if(this.product!=-1){
			try {
				wait();
			} catch (InterruptedException e) {
			 	e.printStackTrace();
			}
		}
		this.product=product;
		System.out.printf("product is set (%d)%n",this.product);
		notify();
	}
	
	public synchronized int getProduct(){
		if(this.product==-1){
			try {
				wait();
			} catch (InterruptedException e) {
			 	e.printStackTrace();
			}
		}
		int p = this.product;
		System.out.printf("consumer is get (%d)%n",this.product);
		this.product = -1;
		notify();
		return p;
	}
}
